<?php
namespace app\common\model;
class Complaint extends Common {
	protected $insert = ['addtime' => SYS_TIME];
	protected function getStatusnameAttr($value, $data) {

		return $data['status'] ? "已处理" : "未处理";
	}

	protected function getAlldataAttr($value, $data) {
		$data['realname'] = model('AdminUser')->where('userid', $data['userid'])->value('username');
		$data['typename'] = $data['typeid'] ? config('SHENSU_TYPE.' . $data['typeid']) : '--';
		$data['cliname'] = $data['clientid'] ? model('Client')->where('id', $data['clientid'])->value('name') : '--';
		$data['adminuser'] = $data['adminid'] ? model('AdminUser')->where('userid', $data['adminid'])->value('username') : '--';
		$data['statusname'] = $data['status'] ? '已回复' : '未回复';
		$data['updatedate'] = $data['updatetime'] ? date('Y-m-d H:i:s', $data['updatetime']) : '未回复';
		$data['adddate'] = $data['addtime'] ? date('Y-m-d H:i:s', $data['addtime']) : '未设置';
		trace($data);
		return $data;
	}
	public function save_datas($data, $uinfo = []) {
		if (!isset($data['clientid']) || !$data['clientid']) {
			$this->setError('请选择要申诉的线索');
			return false;
		}
		if (!isset($data['typeid']) || !$data['typeid']) {
			$this->setError('请选择要申诉的类型');
			return false;
		}
		if (!isset($data['content']) || !$data['content']) {
			$this->setError('请输入要申诉的内容');
			return false;
		}
		$insert = [
			'userid' => $uinfo['userid'],
			'typeid' => $data['typeid'],
			'content' => $data['content'],
			'clientid' => $data['clientid'],
			'dealerid' => $uinfo['dealerid'],
			'images' => $data['images'],
			'linkman' => $data['linkman'],
			'linkphone' => $data['linkphone'],
		];
		return $this->save_data($insert);
	}
}